package com.maimang.platform.dsp.controller;

import com.maimang.platform.annotation.Log;
import com.maimang.platform.base.BaseController;
import com.maimang.platform.base.Result;
import com.maimang.platform.common.utils.ExcelUtil;
import com.maimang.platform.dsp.entity.Budget;
import com.maimang.platform.dsp.service.BudgetService;
import com.maimang.platform.enums.BusinessType;
import com.maimang.platform.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @classname BudgetController
 * @description <br>广告日预算信息操作处理</br>
 * @author  Rocky
 * @date    2019-08-13 15:35:11
 * @email   jintaozhao@qq.com
 * @version 1.0.0
 */
@Controller
@RequestMapping("/dsp/budget")
@Api(value = "广告日预算", description = "广告日预算 信息操作处理接口")
public class BudgetController extends BaseController {
    private String prefix = "dsp/budget";

	@Autowired
	private BudgetService budgetService;

	@RequiresPermissions("dsp:budget:view")
	@GetMapping()
	public String budget() {
	    return prefix + "/budget";
	}

	/**
	 * 查询广告日预算列表
	 */
	@ApiOperation(value = "查询列表", notes = "查询广告日预算列表信息")
	@RequiresPermissions("dsp:budget:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Budget budget) {
		startPage();
        List<Budget> list = budgetService.selectBudgetList(budget);
		return getDataTable(list);
	}


	/**
	 * 导出广告日预算列表
	 */
	@ApiOperation(value = "导出列表", notes = "导出广告日预算列表信息到Excel文件")
	@RequiresPermissions("dsp:budget:export")
    @PostMapping("/export")
    @ResponseBody
    public Result export(Budget budget) {
    	List<Budget> list = budgetService.selectBudgetList(budget);
        ExcelUtil<Budget> util = new ExcelUtil<Budget>(Budget.class);
        return util.exportExcel(list, "budget");
    }

	/**
	 * 新增广告日预算
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}

	/**
	 * 新增保存广告日预算
	 */
	@ApiOperation(value = "新增保存", notes = "参数：Budget")
	@RequiresPermissions("dsp:budget:add")
	@Log(title = "广告日预算", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public Result addSave(Budget budget) {
		return toResult(budgetService.insertBudget(budget));
	}

	/**
	 * 修改广告日预算
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap modelMap) {
		Budget budget = budgetService.selectBudgetById(id);
		modelMap.put("budget", budget);
	    return prefix + "/edit";
	}

	/**
	 * 修改保存广告日预算
	 */
	@ApiOperation(value = "修改保存", notes = "参数：Budget")
	@RequiresPermissions("dsp:budget:edit")
	@Log(title = "广告日预算", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public Result editSave(Budget budget) {
		return toResult(budgetService.updateBudget(budget));
	}

	/**
	 * 删除广告日预算
	 */
	@ApiOperation(value = "删除对象", notes = "参数：ids，示例： id1,id2,id3，接口会转转为String[]类型")
	@RequiresPermissions("dsp:budget:remove")
	@Log(title = "广告日预算", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public Result remove(String ids) {
		return toResult(budgetService.deleteBudgetByIds(ids));
	}

}